package hust.cs.javacourse.search.parse.impl;

import hust.cs.javacourse.search.index.AbstractTerm;
import hust.cs.javacourse.search.index.AbstractTermTuple;
import hust.cs.javacourse.search.index.impl.Term;
import hust.cs.javacourse.search.index.impl.TermTuple;
import hust.cs.javacourse.search.parse.AbstractTermTupleFilter;
import hust.cs.javacourse.search.parse.AbstractTermTupleStream;
import hust.cs.javacourse.search.util.StopWords;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternTermTupleFilter extends AbstractTermTupleFilter {
    /**
     * 构造函数
     * @param input
     */
    public PatternTermTupleFilter(AbstractTermTupleStream input) {
        super(input);
        this.list = input.list;
        List<AbstractTermTuple> newList = new ArrayList<>();
        Pattern pattern = Pattern.compile("[a-zA-Z]+");

        //Pattern p = Pattern.compile("[^a-zA-Z\\s]");
        //Matcher m;
        for(int i = 0;i < this.list.size();i++) {

            if(pattern.matcher(this.list.get(i).term.getContent()).matches())
                newList.add(this.list.get(i));
        }
        this.list = newList;
        //System.out.println(this.list);
    }
    @Override
    public AbstractTermTuple next() {
        if(pos >= list.size())
            return null;
        AbstractTermTuple termTuple = list.get(pos);
        pos++;
        return termTuple;
    }
}
